<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .big{
            position: relative;
            top: 200px;
            left: 200px;
            width: 300px;
            height: 200px;
            background-color: pink;
        }
        .title{
            width: 300px;
            height: 80px;
            background-color: aqua;
            cursor: move;
        }

    </style>
</head>
<body>
    <!-- 模态框 -->
    <div class="big">
        <div class="title"></div>
    </div>

    <script>
        var title=document.querySelector('.title')
        var big=document.querySelector('.big')

        // 获取鼠标在盒子里面的坐标
        title.addEventListener('mousedown',function(e){
             var x=e.pageX - big.offsetLeft;
             var y=e.pageY - big.offsetTop;
             console.log(x,y);

             document.addEventListener('mousemove',move)

             function move(e){
                 big.style.left=e.pageX - x +'px' ;
                 big.style.top=e.pageY - y + 'px' ;
             }

             document.addEventListener('mouseup',function(){
                 document.removeEventListener('mousemove',move)
             })
        })
    </script>

</body>
</html>